package Database;

import java.sql.*;
import java.util.Scanner;

public class Query {
    public static void SongQuery() throws Exception{
        Connection conn = Connect.getConnection();

        String sql = "select * from song";
        Statement smt = conn.createStatement();
        ResultSet rs = smt.executeQuery(sql);

        while(rs.next()){
            System.out.println("Song_id:"+rs.getInt("id")+"  Song_name:"+rs.getString("name"));
        }
        if(rs!=null){
            rs.close();
        }
        if(smt!=null) {
            smt.close();
        }
        if(conn!=null){
            conn.close();
        }
    }

    public  static void FingerQuery() throws Exception{
        Connection conn = Connect.getConnection();

        Scanner in = new Scanner(System.in);
        System.out.println("Input the Song_id");
        int id = in.nextInt();
        String sql = "select * from finger where id=?";
        PreparedStatement psmt = conn.prepareStatement(sql);
        psmt.setInt(1,id);
        ResultSet rs = psmt.executeQuery();

        while (rs.next()){
            System.out.println("Song_id:"+rs.getInt("id")+" Finger_id:"+rs.getInt("finger_id")+" Offset:"+rs.getInt("offset"));
        }
        if(rs!=null){
            rs.close();
        }
        if(psmt!=null){
            psmt.close();
        }
        if(conn!=null){
            conn.close();
        }
    }
}
